﻿using FluentValidation;
using Sgr.UPMS.Application.Commands.UserProfile;
using Sgr.Utilities;

namespace Sgr.UPMS.Application.Validations.UserProfile
{
    /// <summary>
    /// 绑定手机号码命令验证器
    /// </summary>
    public class BindPhoneCommandValidator : AbstractValidator<BindPhoneCommand>
    {
        public BindPhoneCommandValidator()
        {
            // 手机号码验证规则
            RuleFor(x => x.PhoneNumber)
                .NotEmpty().WithMessage("手机号码不能为空")
                .MaximumLength(20).WithMessage("手机号码长度长度不能超过20个字符")
                .Must(phone => RegexHelper.IsValidPhoneNumber(phone))
                .WithMessage("请输入有效的手机号码");

            // 验证码验证
            RuleFor(command => command.VerificationCode)
                .NotEmpty()
                .WithMessage("验证码不能为空")
                .Length(6)
                .WithMessage("验证码必须是6位字符");

            // 用途
            RuleFor(command => command.VerificationPurpose)
                .NotEmpty()
                .WithMessage("用途不能为空")
                .Length(4)
                .WithMessage("用途必须是4位字符");
        }
    }
}